﻿#ifndef __SS_STATE_MACHINE_H__
#define __SS_STATE_MACHINE_H__
#include <map>
#include <memory>

namespace StarSeeker
{

class ssStateMachine
{
public:
	class IState
	{
	public:
		void*	m_onwer;
		int		m_stateID;
		ssStateMachine* m_machine;
		int		m_fromState;

		IState();
		virtual ~IState() {}

		virtual void BeforeUpdate() { }
		virtual void Update(int ms) = 0;
		virtual void OnStateBegin(void* param = 0) { }
		virtual void OnStateEnd() { }
		virtual void OnAttach() { }
	};

	ssStateMachine(void* onwer);
	virtual ~ssStateMachine();
	//更新当前状态
	void Update(int ms);
	//增加状态
	void AddState(const std::shared_ptr<IState>& s, bool isDefault = false);
	//切换状态
	void SwitchState(int stateID, void* param = 0);
	//当前状态ID
	int CurrentStateID();
	//获取状态对象
	std::shared_ptr<IState> GetState(int stateID);
protected:
	void*											m_onwer;		//状态机所有者
	std::map<int, std::shared_ptr<IState> >			m_states;		//所有状态
	std::shared_ptr<IState>							m_currentState;	//当前状态
	std::shared_ptr<IState>							m_defaultState;	//默认状态
public:
	bool											m_pause;		//暂停
};

}
#endif
